package com.user.controller;


import com.user.model.vo.LoginVo;
import com.user.model.vo.UserVo;
import com.user.param.Result;
import com.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Api("用户信息")
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("用户登录")
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public Result login(@Valid @RequestBody LoginVo loginVo, HttpServletResponse response){

        return userService.login(loginVo,response);
    }

    @ApiOperation("用户登出")
    @RequestMapping(value = "/logout",method = RequestMethod.POST)
    public Result logout(){
        return userService.logout();
    }

    @ApiOperation("获取验证码")
    @RequestMapping(value = "/verification",method = RequestMethod.POST)
    public Result getVerificationCode(){
        return userService.getVerificationCode();
    }


    @ApiOperation("用户注册")
    @RequestMapping(value = "/registered",method = RequestMethod.POST)
    public Result registeredUser(@RequestBody @Valid UserVo userVo){
        return userService.registeredUser(userVo);
    }


    @ApiOperation("用户列表")
    @RequestMapping(value = "/userList",method = RequestMethod.POST)
    public Result userList(){
        return userService.userList();
    }


    @ApiOperation("个人信息")
    @RequestMapping(value = "/userInfo",method = RequestMethod.POST)
    public Result userInfo(){
        return userService.userInfo();
    }

}
